package com.bjpowernode.javaweb.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

@WebServlet(name="hello",urlPatterns={"/hello1","/hello2","/hello3"},loadOnStartup = 1,
initParams = {@WebInitParam(name="user",value ="123"),@WebInitParam(name="password",value ="admin")})
public class HelloServlet extends HttpServlet {
    public HelloServlet() {
        System.out.println("HelloServlet的无参数构造方法启用了");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out= response.getWriter();
        String servletName = getServletName();
        out.println(servletName+"</br>");
        String path=request.getServletPath();
        out.println(path+"</br>");

        Enumeration<String> parameterNames = getInitParameterNames();
        while (parameterNames.hasMoreElements()){
            String name=parameterNames.nextElement();
            out.println(name+"="+getInitParameter(name));
        }
    }
}
